﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace CriptoHash.Connection
{
    public abstract class Conector
    {
        public static bool DEBUG = false;

        private Socket _socket;
        protected Socket Socket
        {
            get { return _socket; }
            set { _socket = value; }
        }

        private TcpClient _tcpClient;
        protected TcpClient TcpClient
        {
            get { return _tcpClient; }
            set { _tcpClient = value; }
        }

        private TcpListener _tcpListener;
        protected TcpListener TcpListener
        {
            get { return _tcpListener; }
            set { _tcpListener = value; }
        }

        private NetworkStream _networkStream;
        protected NetworkStream NetworkStream
        {
            get { return _networkStream; }
            set { _networkStream = value; }
        }

        private BinaryWriter _binaryWriter;
        protected BinaryWriter BinaryWriter
        {
            get { return _binaryWriter; }
            set { _binaryWriter = value; }
        }
        private BinaryReader _binaryReader;

        protected BinaryReader BinaryReader
        {
            get { return _binaryReader; }
            set { _binaryReader = value; }
        }

        private string _ip;
        public string Ip
        {
            get { return _ip; }
            set { _ip = value; }
        }

        private int _porta;
        public int Porta
        {
            get { return _porta; }
            set { _porta = value; }
        }

        private bool _conectado;
        public bool Conectado
        {
            get { return _conectado; }
            set { _conectado = value; }
        }

        public Conector(string Ip, int Porta)
        {
            this.Ip = Ip;
            this.Porta = Porta;

            Conectado = false;
        }

        public abstract bool conectar();

        public abstract void desconectar();

        public abstract void enviarMensagem(string mensagem);

        public abstract string receberMensagem();

        public bool mensagemDisponivel()
        {
            return NetworkStream.DataAvailable;
        }
    }
}
